package com.sunnyweather.android.logic.network

import com.sunnyweather.android.logic.network.service.PlacesService
import com.sunnyweather.android.logic.network.service.WeatherService
import com.sunnyweather.android.logic.util.awaitTest
import retrofit2.await

object SunnyWeatherNetWork {
    //获取所有网络访问的Service
    private val placesService=ServiceCreator.create<PlacesService>()
    private val weatherService=ServiceCreator.create<WeatherService>()




    //包装网络访问函数，这些函数全部是挂起函数，必须在协程中使用
    //await()函数在新版本的retrofit中已经被实现了。不需要我们手动去实现了。
    suspend fun queryplaces(query:String)= placesService.queryPlaces(query).await()

    suspend fun getRealTimeWeather(lat:Double,lng:Double)= weatherService.getRealTimeWeather(lat,lng).await()

    suspend fun getDailyWeather(lat:Double,lng:Double)= weatherService.getDailyWeather(lat,lng).await()
}